<!DOCTYPE html>
<html lang="en">
<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="ycngu的博客">
    <meta name="keyword" content="noob">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <title>
        
        为什么不直接用VW而是用rem？ - ycngu的博客 | Ycngu&#39;s Blog
        
    </title>

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/aircloud.css">
    <link rel="stylesheet" href="/css/gitment.css">
    <!--<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">-->
    <link href="//at.alicdn.com/t/font_620856_pl6z7sid89qkt9.css" rel="stylesheet" type="text/css">
    <!-- ga & ba script hoook -->
    <script></script>
</head>

<body>

<div class="site-nav-toggle" id="site-nav-toggle">
    <button>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
    </button>
</div>

<div class="index-about">
    <i> 菜鸟前端为何要战斗？ </i>
</div>

<div class="index-container">
    
    <div class="index-left">
        
<div class="nav" id="nav">
    <div class="avatar-name">
        <div class="avatar">
            <img src="/img/avatar.jpg">
        </div>
        <div class="name">
            <i>YCNGU</i>
        </div>
    </div>
    <div class="contents" id="nav-content">
        <ul>
            <li>
                <a href="/">
                    <i class="iconfont icon-shouye1"></i>
                    <span>主页</span>
                </a>
            </li>
            <li>
                <a href="/tags">
                    <i class="iconfont icon-biaoqian1"></i>
                    <span>标签</span>
                </a>
            </li>
            <li>
                <a href="/archive">
                    <i class="iconfont icon-guidang2"></i>
                    <span>存档</span>
                </a>
            </li>
            <li>
                <a href="/about/">
                    <i class="iconfont icon-guanyu2"></i>
                    <span>关于</span>
                </a>
            </li>
            
            <li>
                <a id="search">
                    <i class="iconfont icon-sousuo1"></i>
                    <span>搜索</span>
                </a>
            </li>
            
        </ul>
    </div>
    
        <div id="toc" class="toc-article">
    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#为什么不直接用VW而是用rem？"><span class="toc-text">为什么不直接用VW而是用rem？</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#vw和rem的差异"><span class="toc-text">vw和rem的差异</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#rem和vw的兼容性"><span class="toc-text">rem和vw的兼容性</span></a></li></ol></li></ol>
</div>
    
</div>


<div class="search-field" id="search-field">
    <div class="search-container">
        <div class="search-input">
            <span id="esc-search"> <i class="icon-fanhui iconfont"></i></span>
            <input id="search-input">
            <span id="begin-search">搜索</span>
        </div>
        <div class="search-result-container" id="search-result-container">

        </div>
    </div>
</div>
        <div class="index-about-mobile">
            <i> 菜鸟前端为何要战斗？ </i>
        </div>
    </div>
    
    <div class="index-middle">
        <!-- Main Content -->
        


<div class="post-container">
    <div class="post-title">
        为什么不直接用VW而是用rem？
    </div>

    <div class="post-meta">
        <span class="attr">发布于：<span>2019-05-21 18:56:24</span></span>
        
        <span class="attr">标签：/
        
        <a class="tag" href="/tags/#css" title="css">css</a>
        <span>/</span>
        
        <a class="tag" href="/tags/#布局" title="布局">布局</a>
        <span>/</span>
        
        
        </span>
        <span class="attr">访问：<span id="busuanzi_value_page_pv"></span>
</span>

    </div>
    <div class="post-content ">
        <h1 id="为什么不直接用VW而是用rem？"><a href="#为什么不直接用VW而是用rem？" class="headerlink" title="为什么不直接用VW而是用rem？"></a>为什么不直接用VW而是用rem？</h1><p>突然想到了这个问题，自己试着解答一下</p>
<h2 id="vw和rem的差异"><a href="#vw和rem的差异" class="headerlink" title="vw和rem的差异"></a>vw和rem的差异</h2><p>VW是根据视口宽度而定的,1vw等于视口宽度的1%<br>rem则是依据html元素的font-size大小而定，在rem动态方案中，会让html的font-size等于视口宽度，变相实现vw的效果（rem方案一般在窗口resize时会改变html的font-size）</p>
<p>PS:以前我在chrome使用vw，窗口resize，但是vw值并没有改变，现在试了下，vw会随着窗口resize改变。</p>
<h2 id="rem和vw的兼容性"><a href="#rem和vw的兼容性" class="headerlink" title="rem和vw的兼容性"></a>rem和vw的兼容性</h2><p>rem的兼容性比vw的兼容性好，看下图<br><img src="/ycngu.gitee.io/ycngu.gitee.io/2019/05/21/为什么不直接用VW而是用rem？/rem-suit.png" alt="rem-suit.jpg"><br><img src="/ycngu.gitee.io/ycngu.gitee.io/2019/05/21/为什么不直接用VW而是用rem？/vw-suit.png" alt="vw-suit.jpg"></p>
<p>附录：张鑫旭写的一篇关于vw的文章<br><a href="https://www.zhangxinxu.com/wordpress/2016/08/vw-viewport-responsive-layout-typography/" target="_blank" rel="noopener">https://www.zhangxinxu.com/wordpress/2016/08/vw-viewport-responsive-layout-typography/</a></p>

        
        <br>
        <div id="comment-container">
        </div>
        <div id="disqus_thread"></div>

        <div id="lv-container">
        </div>

    </div>
</div>

    </div>
</div>


<footer class="footer">
    <ul class="list-inline text-center">
        
        

        

        

        

        

    </ul>
    
    <p>
        <span>/</span>
        
        <span><a href="https://ycngu.gitee.io/">Ycngu&#39;s Page</a></span>
        <span>/</span>
        
        <span><a href="#">It helps SEO</a></span>
        <span>/</span>
        
    </p>
    
    <p>
        <span id="busuanzi_container_site_pv">
            <span id="busuanzi_value_site_pv"></span>PV
        </span>
        <span id="busuanzi_container_site_uv">
            <span id="busuanzi_value_site_uv"></span>UV
        </span>
        Created By <a href="https://hexo.io/">Hexo</a>  Theme <a href="https://github.com/aircloud/hexo-theme-aircloud">AirCloud</a></p>
</footer>




</body>

<script>
    // We expose some of the variables needed by the front end
    window.hexo_search_path = "search.json"
    window.hexo_root = "/"
    window.isPost = true
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="/js/index.js"></script>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>


    <script>
        /**
         *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
         *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables
        */
        if( '' || '')
        var disqus_config = function () {
            this.page.url = '';  // Replace PAGE_URL with your page's canonical URL variable
            this.page.identifier = ''; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
        };

        (function() { // DON'T EDIT BELOW THIS LINE
            var d = document, s = d.createElement('script');
            s.src = 'https://airclouds-blog.disqus.com/embed.js';
            s.setAttribute('data-timestamp', +new Date());
            (d.head || d.body).appendChild(s);
        })();
    </script>



</html>
